<template>
  <div>
    <el-form :model="searchList" ref="searchList" size="normal">
      <el-row :gutter="20">
        <el-col :span="4" :offset="0">
          <el-form-item label="">
            <el-date-picker v-model="searchList.apply_batch" type="year" value-format="yyyy" size="normal"
              placeholder="选择申报批次" class="wid">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="4" :offset="0">
          <el-form-item label="">
            <el-input v-model="searchList.ensure_dept" placeholder="请输入保障部门" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4" :offset="0">
          <el-form-item label="">
            <el-input v-model="searchList.company_name" placeholder="请输入单位名称" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4" :offset="0">
          <el-form-item label="">
            <el-input v-model="searchList.project_name" placeholder="请输入项目名称" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5" :offset="0">
          <div class="right">
            <el-button type="primary" size="medium" @click="search" :loading="loading">查询</el-button>
            <el-button type="primary" size="medium" @click="expExcel" >导出</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>

    <el-table :data="tableData.results" border stripe :height="offsetHeight" v-loading="loading">
      <el-table-column type="index" label="序号" width="60" align="center">
      </el-table-column>
      <el-table-column prop="ensure_dept" label="保障部门" width="80" align="center">
      </el-table-column>
      <el-table-column prop="company_name" label="单位名称" min-width="150" align="center">
      </el-table-column>
      <el-table-column prop="project_name" label="项目名称" min-width="200" align="center">
      </el-table-column>
      <el-table-column prop="service_pre_amount_sum" label="申请金额"   align="center">
      </el-table-column>
      <el-table-column prop="third_check_amount_sum" label="审核金额"   align="center">
      </el-table-column>
      <el-table-column prop="status" label="审核状态" width="100" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0">单位填报</span>
          <span v-if="scope.row.status == 1">本单位审核</span>
          <span v-if="scope.row.status == 2">保障部门审核</span>
          <span v-if="scope.row.status == 3">内设部门审核</span>
          <span v-if="scope.row.status == 51">电子政务部初审</span>
          <span v-if="scope.row.status == 4">咨询机构审核</span>
          <span v-if="scope.row.status == 52">电子政务部复审</span>
        </template>
      </el-table-column>
      <el-table-column prop="" label="操作" width="400" align="center">
        <template slot-scope="{row}">
          <el-button-group>
            <el-button type="green" size="mini" @click="verifyInfo(row.id)">查看审核意见</el-button>
            <el-button type="primary" size="mini" @click="projectInfo(row.id)">项目信息</el-button>
            <el-button type="primary" size="mini" @click="contract(row.id)">合同信息</el-button>
            <look-pdf-item ref="lookPdf" :buttonName="'查看审核报告'" :size="'mini'" :url="row.audit_report_url">
            </look-pdf-item>
          </el-button-group>
        </template>
      </el-table-column>
    </el-table>
    <div class="page">
      <el-pagination @size-change="pageSizeChange" @current-change="pageNoChange" :page-sizes="[10, 50, 100, 200]"
        :page-size="10" background layout="total, sizes, prev, pager, next" :total="tableData.totalRecord">
      </el-pagination>
    </div>

    <!-- 审核信息 -->
    <el-dialog title="审核信息" :visible.sync="verifyShow" size="70%" @close="cancel" center :destroy-on-close="true">
      <el-table :data="verifyData" border stripe height="400px">
        <el-table-column type="index" label="序号" width="50" align="center">
        </el-table-column>
        <el-table-column label="审核状态" width="100" align="center">
          <template slot-scope="{row}">
            <el-tag :type="row.check_status==='1'?'success':'danger'" effect="light">
              {{row.check_status==='1'?'通过':'驳回'}}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="审核机构" align="center">
        </el-table-column>
        <el-table-column prop="message" label="审核意见" align="center">
        </el-table-column>
        <el-table-column prop="create_date" label="审核时间" width="100" align="center">
          <template slot-scope="{row}">
            {{$util.formatDate(row.create_date,'yyyy-MM-dd')}}
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 项目信息 -->
    <el-drawer title="项目信息" :visible.sync="projectShow" size="70%" center :destroy-on-close="true"
      :wrapperClosable="false">
      <project-item :project-params="projectParams" @cancel="cancel" @init="init"></project-item>
    </el-drawer>
  </div>
</template>
<script>
import ProjectItem from '@/components/Project'
import lookPdfItem from '@/components/Upload/LookPdf1.vue'
import { mapGetters } from 'vuex'
export default {
  name: 'PastDeclaredVerifyProject',
  components: {
    lookPdfItem, ProjectItem
  },
  props: {

  },
  data () {
    // 获取当前年份
    let now = new Date().getFullYear().toString()

    return {
      loading: false,
      saveLoading: false,
      searchList: {
        apply_batch: now
      },
      tableData: [],
      offsetHeight: document.documentElement.clientHeight - 280,
      pageNo: '1',
      pageSize: '10',
      projectShow: false,
      projectParams: {},
      verifyShow: false,
      verifyData: [],
    }
  },
  created () {

  },
  mounted () {
    this.init()
  },
  methods: {
    async expExcel () {

      let url = '/api/ac/maintain/infoProjectService/exportHistoryData?company_code='+this.user.loginName;
      let params = this.searchList;
      if(params.company_name != undefined) {
        url+= "&company_name="+params.company_name;
      }
      if(params.project_name != undefined) {
        url+= "&project_name="+params.project_name;
      }
      if(params.apply_batch != undefined) {
        url+= "&apply_batch="+params.apply_batch;
      }
      if(params.ensure_dept != undefined) {
        url+= "&ensure_dept="+params.ensure_dept;
      }
      window.open(url);
    },
    async init () {
      this.loading = true
      const res = await this.$http('historyYWprojectPage', {
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        ...this.searchList
      })
      this.tableData = res
      this.loading = false
    },
    search () {
      this.pageNo = 1
      this.pageSize = 10
      this.init()
    },
    async verifyInfo (id) {
      this.saveLoading = true
      const res = await this.$http('historyYWporjectLog', {
        project_id: id,
        isFilterCode: true
      })
      this.verifyData = res
      this.verifyShow = true
      this.saveLoading = false
    },
    projectInfo (pid) {
      this.projectShow = true
      this.projectParams = {
        pid: pid,
        switch: this.switch,
      }
    },
    contract (id) {
      this.$emit('contractInfo', id);
    },
    cancel () {
      this.projectShow = false
      this.projectParams = {
      }
      this.verifyShow = false
      this.verifyData = []
    },
    pageNoChange (pageNo) {
      this.pageNo = pageNo
      this.init()
    },
    pageSizeChange (pageSize) {
      this.pageSize = pageSize
      this.init()
    },
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  }
}
</script>
<style lang='scss' scoped>
</style>
